<template>
  <div class="app-container">
    <el-tabs
      v-model="activeTab"
      style="
        position: absolute;
        width: 100%;
        height: 553px;
        top: 0%;
        left: 0.159744%;
        text-align: left;
      "
      :tab-position="tabPosition"
      stretch
    >
      <el-tab-pane name="first" style="height: 474px" label="基本信息">
        <!--按钮-->
        <el-row
          :gutter="10"
          class="mb8"
          style="
            height: 50px;
            width: 100%;
            display: flex;
            justify-content: right;
          "
        >
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getTeacherInfo"></right-toolbar>
          <!-- 确定按钮 -->
          <el-col :span="1.5">
            <el-button
              size="mini"
              v-show="hidden"
              type="primary"
              @click="submitForm"
            >
              确 定
            </el-button>
          </el-col>
          <!-- 取消按钮 -->
          <el-col :span="1.5">
            <el-button
              size="medium"
              plain
              type="primary"
              @click="goBack"
            >
              返 回
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              v-show="hidden"
              type="success"
              plain
              icon="el-icon-success"
              size="mini"
              @click="handleSave"
              v-hasPermi="['teacher:person:add']"
            >保存</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              v-show="hidden"
              type="info"
              plain
              icon="el-icon-circle-close"
              size="mini"
              @click="revoke"
            >取消</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-edit"
              size="mini"
              @click="handleUpdate"
              v-hasPermi="['teacher:personFile:edit']"
            >修改</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              @click="reset"
            >清空</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['teacher:person:export']"
            >导出</el-button
            >
          </el-col>
          <!-- <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
          ></right-toolbar> -->
        </el-row>
        <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          v-show="showSearch"
          label-width="100px"
          style="height: 500px"
        >
<!--          @tab-click="handleClick"-->

          <el-form ref="form" :model="form" :rules="rules" label-width="100px">
            <el-form-item label="照片">
              <imageUpload v-model="form.zdyxa0106" />
            </el-form-item>
            <el-form-item label="姓名" prop="a0101">
              <el-input
                v-show="hidden"
                v-model="form.a0101"
                placeholder="请输入姓名"
                style="width: 220px"
              />
              <div v-show="!hidden">{{ form.a0101 }}</div>
            </el-form-item>
<!--            <el-form-item label="用户ID" prop="userId">-->
<!--              <el-input-->
<!--                v-show="hidden"-->
<!--                v-model="form.userId"-->
<!--                placeholder="请输入用户ID"-->
<!--                style="width: 220px"-->
<!--              />-->
<!--              <div v-show="!hidden">{{ form.userId }}</div>-->
<!--            </el-form-item>-->
            <el-form-item label="教师编号" prop="a0199">
              <el-input
                v-show="hidden"
                v-model="form.a0199"
                placeholder="请输入教师编号"
                style="width: 220px"
              />
              <div v-show="!hidden">{{ form.a0199 }}</div>
            </el-form-item>
            <el-form-item label="性别" prop="a0104">
              <el-select
                v-show="hidden"
                v-model="form.a0104"
                placeholder="请选择性别"
                @visible-change="getSexDict"
              >
                <el-option
                  v-for="dict in a0104Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.a0104 }}</div>
            </el-form-item>
            <el-form-item label="出生日期" prop="a0107">
              <el-date-picker
                v-show="hidden"
                clearable
                size="small"
                v-model="form.a0107"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择出生日期"
              >
              </el-date-picker>
              <div v-show="!hidden">{{ form.a0107 }}</div>
            </el-form-item>
            <el-form-item label="籍贯" prop="a0111b">
              <el-select
                v-show="hidden"
                v-model="form.a0111b"
                placeholder="请选择籍贯"
                filterable
                @visible-change="getPersonPlace"
              >
                <el-option
                  v-for="dict in a0111bOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.zdyxa01110 }}</div>
            </el-form-item>
            <el-form-item label="出生地" prop="a0114b">
              <el-select
                v-show="hidden"
                v-model="form.a0114b"
                placeholder="请选择出生地"
                filterable
                @visible-change="getPersonPlace"
              >
                <el-option
                  v-for="dict in a0114bOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.a0114b }}</div>
            </el-form-item>
            <el-form-item label="民族" prop="a0117">
              <el-select
                v-show="hidden"
                v-model="form.a0117"
                placeholder="请选择民族"
                filterable
                @visible-change="getPersonNationality"
              >
                <el-option
                  v-for="dict in a0117Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.a0117 }}</div>
            </el-form-item>
            <el-form-item label="健康状况" prop="a0127">
              <el-select
                v-show="hidden"
                v-model="form.a0127"
                placeholder="请选择健康状况"
                @visible-change="getPersonHealth"
              >
                <el-option
                  v-for="dict in a0127Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.a0127 }}</div>
            </el-form-item>
            <el-form-item label="婚姻状况" prop="a0131">
              <el-select
                v-show="hidden"
                v-model="form.a0131"
                placeholder="请选择婚姻状况"
                @visible-change="getPersonMarry"
              >
                <el-option
                  v-for="dict in a0131Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.a0131 }}</div>
            </el-form-item>

            <el-form-item label="政治面貌" prop="a0141">
              <el-select
                v-show="hidden"
                v-model="form.a0141"
                placeholder="请选择政治面貌"
                @visible-change="getPersonLandscape"
              >
                <el-option
                  v-for="dict in a0141Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.a0141 }}</div>
            </el-form-item>
            <el-form-item label="户籍所在地" prop="a0181a">
              <el-select
                v-show="hidden"
                v-model="form.a0181a"
                placeholder="请选择户籍所在地"
                filterable
                @visible-change="getPersonPlace"
              >
                <el-option
                  v-for="dict in a0181aOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.a0181a }}</div>
            </el-form-item>
            <el-form-item label="有效证件类别" prop="a0183">
              <el-select
                v-show="hidden"
                v-model="form.a0183"
                placeholder="请选择有效证件类别"
                @visible-change="getPersonCard"
              >
                <el-option
                  v-for="dict in a0183Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.a0183 }}</div>
            </el-form-item>
            <el-form-item label="身份证号" prop="a0184">
              <el-input
                v-show="hidden"
                v-model="form.a0184"
                placeholder="请输入身份证号"
                style="width: 220px"
              />
              <div v-show="!hidden">{{ form.a0184 }}</div>
            </el-form-item>
<!--            <el-form-item label="删除标识" prop="delFlag">-->
<!--              <el-input-->
<!--                v-show="hidden"-->
<!--                v-model="form.delFlag"-->
<!--                placeholder="请输入删除标识"-->
<!--                style="width: 220px"-->
<!--              />-->
<!--              <div v-show="!hidden">{{ form.delFlag }}</div>-->
<!--            </el-form-item>-->

<!--            <el-form-item label="人员现状" prop="zdyxa0109">-->
<!--              <el-input-->
<!--                v-show="hidden"-->
<!--                v-model="form.zdyxa0109"-->
<!--                placeholder="请输入人员现状"-->
<!--                style="width: 220px"-->
<!--              />-->
<!--              <div v-show="!hidden">{{ form.zdyxa0109 }}</div>-->
<!--            </el-form-item>-->
            <el-form-item label="进入本校时间" prop="zdyxa01110">
              <el-date-picker
                v-show="hidden"
                clearable
                size="small"
                v-model="form.zdyxa01110"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择进入本校时间"
              >
              </el-date-picker>
              <div v-show="!hidden">{{ form.zdyxa01110 }}</div>
            </el-form-item>
            <el-form-item label="参加工作日期" prop="a0134" height="36px">
              <el-date-picker
                v-show="hidden"
                clearable
                size="small"
                v-model="form.a0134"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择参加工作日期"
              >
              </el-date-picker>
              <div v-show="!hidden">{{ form.a0134 }}</div>
            </el-form-item>
            <el-form-item v-show="hidden" label="附件" prop="remark" style="width: 100%">
              <fileUpload v-model="form.remark"/>
              <div v-show="!hidden">{{ form.remark }}</div>
            </el-form-item>
          </el-form>
        </el-form>
      </el-tab-pane>
      <el-tab-pane
        name="second"
        style="height: 474px"
        label="教育背景"
      >
          <degree/>
      </el-tab-pane>
      <el-tab-pane
        name="three"
        style="height: 475px"
        label="工作经历"
      >
        <work/>
      </el-tab-pane>
      <el-tab-pane
        name="four"
        style="height: 473px"
        label="职称信息"
      >
      <PersonTitle/>
      </el-tab-pane>
      <el-tab-pane
        name="five"
        style="height: 472px"
        label="年度考核"
      >
      <Assessment/>
      </el-tab-pane>
      <el-tab-pane
        name="six"
        style="height: 472px"
        label="培训情况"
      >
          <Train/>
      </el-tab-pane>
      <el-tab-pane
        name="seven"
        style="height: 472px"
        label="档案信息"
      >
        <PersonFile/>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import {
  getTeacherInfo,
  getPerson,
  delPerson,
  addPerson,
  updatePerson,
  exportPerson,
  selectDegreeByA00,
  selectWorkInfoByA00,
  selectTitleByA00,
  selectTrainByA00,
  selectAssessmentByA00,
  selectFileByA00, selectAppendixByA00, exportSelf,
} from "@/api/teacher/person";
import ImageUpload from "@/components/ImageUpload";
import FileUpload from "@/components/FileUpload";
import Degree from "@/views/teacher/degree/index";
import Work from "@/views/teacher/work/index";
import PersonTitle from "@/views/teacher/personTitle/index";
import Assessment from "@/views/teacher/assessment/index";
import Train from "@/views/teacher/train/index";
import PersonFile from "@/views/teacher/personFile/index";

export default {
  name: "Person",
  components: {
    ImageUpload,
    FileUpload,
    Degree,
    Work,
    PersonTitle,
    Assessment,
    Train,
    PersonFile
  },
  data() {
    return {
      hidden: false,
      activeTab: "first",
      tabPosition: "top",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 教师基本信息表格数据
      personList: [],
      //教育信息
      educationList: [],
      //工作经历
      workInfoList: [],
      //职称信息
      personTitleList: [],
      //培训情况
      trainInfoList: [],
      //考核信息
      assessmentList: [],
      //档案信息
      personFileList: [],
      //附件材料
      appendixList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //基本信息字典值
      // 性别字典
      a0104Options: [],
      // 籍贯字典
      a0111bOptions: [],
      // 出生地字典
      a0114bOptions: [],
      // 民族字典
      a0117Options: [],
      // 健康状况字典
      a0127Options: [],
      // 婚姻状况字典
      a0131Options: [],
      // 政治面貌字典
      a0141Options: [],
      // 户籍所在地字典
      a0181aOptions: [],
      // 有效证件类别字典
      a0183Options: [],
      //教育背景字典值
      // 学历字典
      a0801Options: [],
      // 学习完成情况字典
      a0811Options: [],
      // 所学专业类别字典
      a0820Options: [],
      // 学位字典
      a0830Options: [],
      // 教育类别字典
      a0837Options: [],
      // 第二学位所学专业类别字典
      a0840Options: [],
      //工作经历字典值
      // 任职状态字典
      a0255Options: [],
      //职称字典值
      // 专业技术资格名称字典
      a0601Options: [],
      // 职称级别字典
      a0601cOptions: [],
      // 考核周期字典
      zdyja10303Options: [],
      // 培训类别字典
      a1101Options: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        // userId: 115,
        a0101: null,
        a0104: null,
        a0141: null,
        a0199: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        a00: [
          { required: true, message: "人员标识符不能为空", trigger: "blur" },
        ],
        a0101: [{ required: true, message: "姓名不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    console.log(this.$route.query);
    // this.userId = this.$route.query.userId;
    this.A00 = this.$route.query.A00;
    this.getTeacherInfo();
  },
  methods: {
    /** 点击下拉框时查询对应字典值 */
    getPersonCard() {
      this.getDicts("sys_person_card").then((response) => {
        this.a0183Options = response.data;
      });
    },
    getPersonLandscape() {
      this.getDicts("sys_person_landscape").then((response) => {
        this.a0141Options = response.data;
      });
    },
    getPersonMarry() {
      this.getDicts("sys_person_marry").then((response) => {
        this.a0131Options = response.data;
      });
    },
    getPersonHealth() {
      this.getDicts("sys_person_health").then((response) => {
        this.a0127Options = response.data;
      });
    },
    getPersonNationality() {
      this.getDicts("sys_person_nationality").then((response) => {
        this.a0117Options = response.data;
      });
    },
    getPersonPlace(){
      this.getDicts("sys_person_place").then((response) => {
        this.a0111bOptions = response.data;
        this.a0114bOptions = response.data;
        this.a0181aOptions = response.data;
      });
    },
    getSexDict() {
      this.getDicts("sys_user_sex").then((response) => {
        this.a0104Options = response.data;
      });
    },
    // handleClick() {
    //   console.log('111');
    //   this.getTeacherInfo();
    // },
    //通过路由传参A00获取教师基本信息
    getTeacherInfo() {
      this.A00 = this.$route.query.A00
      getTeacherInfo(this.A00).then((response) => {
        this.form = response.data;
      });
    },
    //获取教育背景
    getDegree() {
      this.A00 = this.$route.query.A00
      selectDegreeByA00(this.A00).then((response) => {
        this.educationList = response.rows;
      });
    },
    //获取工作经历
    getWorkInfo() {
      this.A00 = this.$route.query.A00
      selectWorkInfoByA00(this.A00).then((response) => {
        this.workInfoList = response.rows;
      });
    },
    //获取职称信息
    getTitle() {
      this.A00 = this.$route.query.A00
      selectTitleByA00(this.A00).then((response) => {
        this.personTitleList = response.rows;
      });
    },
    //获取培训情况
    getTrainInfo() {
      this.A00 = this.$route.query.A00
      selectTrainByA00(this.A00).then((response) => {
        this.trainInfoList = response.rows;
      });
    },
    //获取考核信息
    getAssessment() {
      this.A00 = this.$route.query.A00
      selectAssessmentByA00(this.A00).then((response) => {
        this.assessmentList = response.rows;
      });
    },
    //获取档案
    getPersonFile() {
      this.A00 = this.$route.query.A00
      selectFileByA00(this.A00).then((response) => {
        this.personFileList = response.rows;
      });
    },
    //获取附件材料
    getAppendix() {
      this.A00 = this.$route.query.A00
      selectAppendixByA00(this.A00).then((response) => {
        this.appendixList = response.rows;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 撤销按钮
    revoke() {
      this.hidden = false;
      this.getTeacherInfo();
    },
    // 表单重置
    reset() {
      this.hidden = false;
      this.form = {
        a00: null,
        a0101: null,
        userId: null,
        a0104: null,
        a0107: null,
        a0111b: null,
        a0114b: null,
        a0117: null,
        a0127: null,
        a0131: null,
        a0134: null,
        a0141: null,
        a0181a: null,
        a0183: null,
        a0184: null,
        a0199: null,
        zdyxa0106: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        remark: null,
        zdyxa0109: null,
        zdyxa01110: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getTeacherInfo();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      // this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.a00);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 保存按钮操作 */
    handleSave () {
      localStorage.setItem("form",JSON.stringify(this.form));
      this.hidden = false;
    },
    /** 修改按钮操作 */
    // handleRevoke() {
    //   this.xiugaibasic = false;
    // },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.hidden = true;
      // const a00 = row.a00;
      // getTeacherInfo(a00).then((response) => {
      //   this.form = response.data;
      //   this.title = "修改教师基本信息";
      // });
    },
    /** 返回页面 */
    goBack() {
      // 关闭当前标签页并返回上个页面
      this.$store.dispatch("tagsView/delView", this.$route);
      this.$router.go(-1)
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.a00 != null) {
            updatePerson(this.form).then((response) => {
              this.loading = true;
              this.msgSuccess("修改成功");
              this.hidden = false;
              this.open = false;
              this.getTeacherInfo();
            });
          } else {
            addPerson(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getTeacherInfo();
            });
          }
        }
      });
      // setTimeout(() => {
      //   this.revoke();
      // }, 3000);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const a00s = row.a00 || this.ids;
      this.$confirm(
        '是否确认删除教师基本信息编号为"' + a00s + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delPerson(a00s);
        })
        .then(() => {
          this.getTeacherInfo();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      let A00 = this.A00;
      this.$confirm("是否确认导出所有教师基本信息数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportSelf(A00);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
  },
};
</script>
<style>
::v-deep .el-tabs__nav-scroll {
  width: 50% !important;
  margin: 0 auto !important;
}
.el-form--inline .el-form-item {
  width: 31%;
  float: left;
}
.el-form-item--medium .el-form-item__content {
  margin-left: 30px !important;
}
.el-form-item {
  margin-bottom: 45px;
}
</style>
